package com.lanqiao.gxnushop.mapper;

import com.lanqiao.gxnushop.entity.CartItems;
import com.lanqiao.gxnushop.valueObject.CarProduct;
import io.swagger.v3.oas.annotations.media.Schema;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

@Schema(description ="购物车")
@Mapper
public interface CartItemsMapper {

    @Schema(description ="添加购物车")
    @Insert("insert into cartItems(cartItemId,buyerId,productId,quantity) values (#{cartItemId},#{buyerId},#{productId},#{quantity})")
    boolean add(CartItems cartItems);

    @Schema(description ="购物车无用索引删除购物车")
    @Delete("delete from cartItems where cartItemId=#{cartItemId}")
    boolean delete(String cartItemId);


    /*@Schema(description ="根据购物车商品id查询购物车")
    @Insert("select * from cart_items where cartItemId=#{cartItemId}")
    CartItems findById(String cartItemId);*/

    @Schema(description ="根据买家id查询购物车")
    @Select("select cartItemId, products.*,cartitems.buyerId as buyerId,cartitems.quantity as quantity from products join cartitems on (products.productId = cartitems.productId)\n" +
            "\t\twhere products.state = '1' and cartitems.buyerId = #{buyerId}")
    ArrayList<CarProduct> findByBuyerId(String buyerId);

    @Schema(description ="更新购物车")
    @Update("update cartItems set quantity=#{quantity} where cartItemId=#{cartItemId}")
    boolean update(CartItems cartItems);

}
